package com.zyf.connotation.utils

import android.content.Context

/**
 * 作者：Think
 * 创建于 2017/6/1 16:55
 */
object ShardUtil{
    var conn = "connotation"
    /**
     * 保存一个key方法
     * @param key
     * *
     * @param value
     */
    fun savePreferenceString(context: Context, key: String, value: String) {
        val preferences = context.getSharedPreferences(conn,
                0)
        val editor = preferences.edit()
        editor.putString(key, value)
        editor.commit()
    }

    /**读取一个key String值方法  默认Mode 为0

     * @param key
     * *
     * @return
     */
    fun getPreferenceString(context: Context, key: String): String {
        val preferences = context.getSharedPreferences(conn,
                0)
        return preferences.getString(key, "")

    }

    /**
     * 设置SharedPreferences名,不设置时默认为userinfo
     * @param key
     * *
     * @param value
     */
    fun savePreferenceBoolean(context: Context, key: String, value: Boolean) {
        val preferences = context.getSharedPreferences(conn, 0)

        val editor = preferences.edit()
        editor.putBoolean(key, value)
        editor.commit()
    }

    /**
     * 读取一个key Boolean值方法  默认为false
     * @param key
     * *
     * @return
     */
    fun getPreferenceBoolean(context: Context, key: String): Boolean {
        val preferences = context.getSharedPreferences(conn,
                0)
        return preferences.getBoolean(key, false)
    }
    /**
     * 设置SharedPreferences名,不设置时默认为userinfo
     * @param key
     * *
     * @param value
     */
    fun savePreferenceInt(context: Context, key: String, value: Int) {
        val preferences = context.getSharedPreferences(conn, 0)

        val editor = preferences.edit()
        editor.putInt(key, value)
        editor.commit()
    }

    /**
     * 读取一个key Int值方法  默认为0
     * @param key
     * *
     * @return
     */
    fun getPreferenceInt(context: Context, key: String): Int {
        val preferences = context.getSharedPreferences(conn,
                0)
        return preferences.getInt(key, 0)
    }
}